<?php
	
	if(!defined("IN_APP"))
	{
		exit;
	}
	
	if(!adminpermission('X','100000'))
	{
		echo '无权查看!';
		exit;
	}
	
	$method = getParam('m','get','list');
	
	$parm = requestArrayParm($_REQUEST);
	
	$fTitle = "系统配置";
	$sTitle = "角色列表";
	
	if($method == 'list')
	{
		unset($search,$pages,$sorts,$list);
		
		$search['status'] = array('in','1,2');
		
		if(!empty($parm['keyword']))
		{
			$search['name'] = array('like',$parm['keyword']);
		}
		
		$page = $pages['page'] = getParam('page','request','1');
		
		$pages['rows'] = 20;
		
		$sorts['addtime'] = 'desc';
		
		$resData = _SqlTool::getList('role', $search, $pages, $sorts);
		
		//查询对应的数据
		
		foreach ($resData['list']  as $key => $value)
		{
			unset($search);
			$wheres['id'] = $value['adduser'];
			$info = _SqlTool::getInfo('admin', $wheres);
			$value['createUser'] = $info['nickname'];
			$list[] = $value;
		}
		
		$pageurl = SITE_URL.'index.php?'.set_URL_Param(get_URL_Param());
	
		$pagetotal = $resData["pages"];
		
		include renderTemplate('system/rolelist');
	}
	
	if($method == 'add')
	{
		unset($sysMenuList['Z']);
		$list = $sysMenuList;
		$tTitle = '添加角色信息';
		include renderTemplate('system/role');
	}
	
	if($method == 'edit')
	{
		$tTitle = '编辑角色信息';
		
		if($parm['id'])
		{
			unset($where,$data);
			$where['id'] = $parm['id'];
			$role = _SqlTool::getInfo('role', $where);
			if($role)
			{
				$list = $sysMenuList;
				
				$role['permission'] = json_decode($role['permission'],true);
				
			}
			else
			{
				header("Location:".SITE_URL.'index.php?a=roleM');
			}
		}
		else
		{
			header("Location:".SITE_URL.'index.php?a=roleM');
		}
		include renderTemplate('system/role');
	}
	
	